package org.esgl3d.util;



public class FpsCounter {
	private int lastFps = 0;
	private int currentFps;
	private int lastDelta = 0;
	private long lastMillis = System.currentTimeMillis();
	private long lastNextMillis = System.currentTimeMillis();
	private String lastFpsString = "";
	
	public int getLastFps() {
		return lastFps;
	}
	
	public int getLastDelta() {
		return lastDelta;
	}
	
	public void next() {
		currentFps++;
		if (System.currentTimeMillis() > lastMillis+1000) {
			if (lastFps != currentFps)
				lastFpsString = String.format("FPS: %d", currentFps);
			
			lastFps = currentFps;
						
			currentFps = 0;
			lastMillis = System.currentTimeMillis();
		}
		
		lastDelta = (int)(System.currentTimeMillis() - lastNextMillis);
		lastNextMillis = System.currentTimeMillis();
	}
	
	@Override
	public String toString() {
		return lastFpsString;
	}
}
